package net.lovesrc.allin.jobs.backup;

import com.alibaba.fastjson.JSONObject;
import net.lovesrc.allin.biz.gt.GtService;
import net.lovesrc.allin.jobs.base.BaseJob;
import org.apache.commons.lang3.RandomUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Profile;

import java.util.Date;
import java.util.List;

//@Component
@Profile("live")
public class GtAuthIdJob extends BaseJob {

    @Autowired
    private GtService gtService;

    @Override
    public void runOnce() {
        // 实名
        {
            List<JSONObject> rows = queryForRows(jdbcTemplate, "select * from t_gt_account where idStatus is null and registerTime < ?", DateUtils.addMinutes(new Date(), -10));
            for (JSONObject row : rows) {
                gtService.authId(row.getString("mobile"));
            }
        }
        // 同步实名状态
        {
            List<JSONObject> rows = queryForRows(jdbcTemplate, "select * from t_gt_account where idStatus = 'submitted' and idTime < ?", DateUtils.addMinutes(new Date(), -10));
            for (JSONObject row : rows) {
                gtService.syncStatus(row.getString("mobile"));
            }
        }
    }

    @Override
    protected long intervalMilliseconds() {
        return 1000 * RandomUtils.nextInt(60, 120);
    }

}
